package com.itcast.controller;

import com.itcast.pojo.Emp;
import com.itcast.pojo.LoginInfo;
import com.itcast.pojo.Result;
import com.itcast.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LoginController {

    @Autowired
    private EmpService empService;

    /**
     * 员工登录
     * @param emp
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("员工登录,{}",emp.getName());//注意不要传emp对象,因为其中包含敏感信息
        LoginInfo loginInfo = empService.login(emp);
        //判断用户是否为空
        if (loginInfo!=null){
            return Result.success(loginInfo);
        }
        return Result.error("用户名或密码错误，请重试");
    }
}
